﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DiveManager
{
    public partial class Rental_GroupEdit : Form
    {
        public string id_weitergabe;

        
        protected DiveDatabaseEntities diveDatabase;
        protected BindingSource bindingSource;

        
        public Rental_GroupEdit()
        {
            InitializeComponent();

            // Init Database
            diveDatabase = new DiveDatabaseEntities();
            bindingSource = new BindingSource();

        }

        public string Weitergabe_Details
        {
            get;
            set;
        }

        private void Rental_GroupEdit_Load(object sender, EventArgs e)
        {

            this.id_weitergabe = Weitergabe_Details;

            
            Guid id_guid = new Guid(id_weitergabe);
            
            //Abfrage in Rantal_Group DB
            var query = from rg in diveDatabase.Rental_Group
                        where rg.ID == id_guid
                        select rg;

            foreach (var r in query)
            {
                txGroupname.Text = r.Name;
                txDescription.Text = r.Bezeichnung;
                txClub.Text = r.Preis_Club.ToString();
                txNormal.Text = r.Preis_Normal.ToString();
                //DSD_Sort Fehlt
            }


        }

        

        private void btExit_Click(object sender, EventArgs e)
        {
            //Form schließen
            this.Close();
        }

        private void btSubmit_Click(object sender, EventArgs e)
        {

            //Aus id_search eine GUID machen
            Guid id_guid = new Guid(id_weitergabe);

            //Schreiben in DB
            //Schreiben in Supplier_Main
            var edit_rg = from rg in diveDatabase.Rental_Group
                          where rg.ID == id_guid
                          select rg;

            foreach (Rental_Group rg in edit_rg)
            {
                rg.Name = txGroupname.Text;
                rg.Bezeichnung = txDescription.Text;
                rg.Preis_Normal = System.Convert.ToDouble(txNormal.Text);
                rg.Preis_Club = System.Convert.ToDouble(txClub.Text);


            }

            diveDatabase.SaveChanges();

            MessageBox.Show("Gruppe geändert");
            this.Close();



        
        }

        private void GroupList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
           
        }
    }
}
